const express = require('express');
const { RouteBuilder } = require('../utils/routeDecorator');
const router = express.Router();

// 使用RouteBuilder创建带文档的路由
const productRoutes = new RouteBuilder('Products')
  .get('/', '获取产品列表', {
    parameters: [
      {
        in: 'query',
        name: 'category',
        type: 'string',
        description: '产品分类'
      },
      {
        in: 'query',
        name: 'page',
        type: 'integer',
        default: 1,
        description: '页码'
      }
    ],
    responses: {
      200: {
        description: '成功获取产品列表',
        schema: 'ApiResponse'
      }
    }
  }, async (req, res) => {
    res.json({
      success: true,
      message: '获取产品列表成功',
      data: []
    });
  })
  .post('/', '创建新产品', {
    requestBody: {
      type: 'object',
      properties: {
        name: { type: 'string', description: '产品名称' },
        price: { type: 'number', description: '产品价格' },
        category: { type: 'string', description: '产品分类' }
      }
    },
    responses: {
      201: {
        description: '产品创建成功'
      }
    }
  }, async (req, res) => {
    res.status(201).json({
      success: true,
      message: '产品创建成功',
      data: { id: Date.now(), ...req.body }
    });
  })
  .build(router);

// 打印生成的文档
console.log('生成的Swagger文档:');
console.log(new RouteBuilder('Products').generateDocs());

module.exports = router;